<template>
  <el-card class="category">
    <el-form :inline="true" :model="formInline" class="demo-form-inline" :disabled="!disabledSelector">
        <el-form-item label="一级分类">
            <el-select v-model="category1Id" placeholder="请选择">
                <el-option v-for="c1 in categorySelectorInfoStore.category1List" :key="c1.id" :value="c1.id" :label="c1.name"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="二级分类">
          <el-select v-model="category2Id" placeholder="请选择">
                <el-option v-for="c2 in categorySelectorInfoStore.category2List" :key="c2.id" :value="c2.id" :label="c2.name"></el-option>
            </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
                <el-option v-for="c3 in categorySelectorInfoStore.category3List" :key="c3.id" :value="c3.id" :label="c3.name"></el-option>
            </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang='ts'>
export default {
    name: 'categorySelector'
}
</script>
<script lang='ts' setup>
import { onMounted, reactive,computed  } from 'vue';
import {useCategorySelectorInfoStore} from '@/stores/categorySelector'  
defineProps(['disabledSelector'])
onMounted(()=>{
  categorySelectorInfoStore.getCategory1ListData()
})
const categorySelectorInfoStore = useCategorySelectorInfoStore()

const category1Id = computed({
    get(){
        return categorySelectorInfoStore.category1Id as number
    },
    set(val){
        categorySelectorInfoStore.getCategory2ListData(val)
    }
})

const category2Id = computed({
    get(){
        return categorySelectorInfoStore.category2Id as number
    },
    set(val){
        categorySelectorInfoStore.getCategory3ListData(val)
    }
})

const category3Id = computed({
    get(){ 
        return categorySelectorInfoStore.category3Id as number
    },
    set(val){
        categorySelectorInfoStore.setCategory3Id(val)
    }
})

const formInline = reactive({
    user:'',
    region:''
})
const onSubmit=()=>{
    console.log('submit')
}
</script>


<style lang='scss' scoped>
.category {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>